//
//  UIButton+PK.swift
//  GoAbroad
//
//  Created by Pink Snow on 2025/5/14.
//

import UIKit

extension UIButton {
    
    /// 配置按钮的通用样式
    /// - Parameters:
    ///   - title: 按钮标题
    ///   - state: 按钮状态（默认 `.normal`）
    ///   - fontSize: 字体大小
    ///   - cornerRadius: 圆角半径
    ///   - backgroundColor: 背景颜色
    ///   - tintColor: 文本或图标颜色
    ///   - isEnabled: 是否可用
    func configure(
        title: String,
        for state: UIControl.State = .normal,
        fontSize: CGFloat = 16,
        cornerRadius: CGFloat = 8,
        backgroundColor: UIColor = .systemBlue,
        tintColor: UIColor = .white,
        isEnabled: Bool = true
    ) {
        self.setTitle(title, for: state)
        self.titleLabel?.font = UIFont.systemFont(ofSize: fontSize, weight: .medium)
        self.layer.cornerRadius = cornerRadius
        self.backgroundColor = backgroundColor
        self.tintColor = tintColor
        self.isEnabled = isEnabled
    }
    
    /// 快速创建一个配置好的 UIButton
    static func create(
        type: UIButton.ButtonType = .system,
        title: String,
        state: UIControl.State = .normal,
        fontSize: CGFloat = 16,
        cornerRadius: CGFloat = 8,
        backgroundColor: UIColor = .systemBlue,
        tintColor: UIColor = .white,
        isEnabled: Bool = true
    ) -> UIButton {
        let button = UIButton(type: type)
        button.configure(
            title: title,
            for: state,
            fontSize: fontSize,
            cornerRadius: cornerRadius,
            backgroundColor: backgroundColor,
            tintColor: tintColor,
            isEnabled: isEnabled
        )
        return button
    }
}
